package ${packageName}.controller;

import com.example.book.base.BaseController;
import com.example.book.base.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import ${packageName}.entity.${className};
import ${packageName}.service.${className}Service;


/**
 * @author   ${author!'admin'}
 * @date ${createTime}
*/
@Controller
@RequestMapping(value = "/${className1}")
public class ${className}Controller extends BaseController{

    @Autowired
    private ${className}Service ${className1}Service;

    @ModelAttribute
    public ${className} get(@RequestParam(required=false) String id) {
        if (StringUtils.isNotBlank(id)){
            ${className} ${className1} = new ${className}();
            ${className1}.setId(id);
            return ${className1}Service.get(${className1});
        }else{
            return new ${className}();
        }
    }

    @RequestMapping(value = "/get")
    @ResponseBody
    public ${className} getById(${className} ${className1}) {
        return ${className1};
    }

    @RequestMapping(value = "/list")
    public String list(${className} ${className1}) {
        return "${className1}";
    }

    @RequestMapping(value = "/info")
    @ResponseBody
    public List<${className}> info(${className} ${className1}) {
        return ${className1}Service.findList(${className1});
    }


    @RequestMapping(value = "/findPage")
    @ResponseBody
    public PageInfo<${className}> findPage(${className} ${className1}) {
        return  ${className1}Service.findPage( ${className1});
    }

    @RequestMapping(value = "/save")
    @ResponseBody
    public Result save(${className} ${className1}) {
        ${className1}Service.save(${className1});
        return Result.success("保存成功");
    }

    @RequestMapping(value = "/logicalDeletion",method = RequestMethod.POST)
    @ResponseBody
    public Result logicalDeletion(@RequestParam("id") String id){
        ${className1}Service.logicalDeletion(id);
        return Result.success();
    }

    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@RequestParam("ids") String[] ids){
        ${className1}Service.delete(ids);
        return Result.success();
    }

}